#include <bits/stdc++.h>
using namespace std;
int goods[30020] = {0};
int have[30020] = {0};
int main(void)
{
    int w, n, temp, sum = 0, ans = 0;
    cin >> w >> n;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &goods[i]);
    }
    sort(goods, goods + n);
    for (int i = n - 1; i >= 0; i--)
    {
        if (!have[i])
        {
            have[i] = 1;
            sum = goods[i];
            for(int j = i - 1; j>=0 ;j--){
                if(sum + goods[j] <= w && !have[j]){
                    sum += goods[j];
                    have[j] = 1;
                }
            }
            ans ++;
        }
    }
    cout << ans;
    return 0;
}